package com.ruoyi.kjy.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.kjy.domain.EnterpriseActivity;
import com.ruoyi.kjy.domain.NewEnterprise;
import com.ruoyi.kjy.service.EnterpriseActivityService;
import com.ruoyi.kjy.service.NewEnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Objects;

/**
 * @Description:
 * @Author: Hi，Wang
 * @Date: 10/26,0026 19:39
 */

@RestController
@RequestMapping("/enterpriseActivity")
public class EnterpriseActivityController extends BaseController {



    @Autowired
    private EnterpriseActivityService enterpriseActivityService;

    @GetMapping("/list")
    public AjaxResult list(Long current, Long size, EnterpriseActivity enterpriseActivity) {
        QueryWrapper<EnterpriseActivity> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(enterpriseActivity);
        if (Objects.isNull(current)) {
            current = 1l;
        }
        if (Objects.isNull(size)) {
            size = 10l;
        }
        if (size >= 20l) {
            size = 20l;
        }
        return AjaxResult.success(enterpriseActivityService.page(new Page<>(current, size), queryWrapper));
    }




    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(enterpriseActivityService.getById(id));
    }


    @Log(title = "企业活动", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EnterpriseActivity enterpriseActivity) {
        enterpriseActivity.setStatus(0);
        boolean save = enterpriseActivityService.save(enterpriseActivity);
        return toAjax(save);
    }

    @Log(title = "企业活动", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EnterpriseActivity enterpriseActivity) {
        return toAjax(enterpriseActivityService.updateById(enterpriseActivity));
    }

    @Log(title = "新设企业", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable(value = "ids") Long[] ids) {
        return toAjax(enterpriseActivityService.removeByIds(Arrays.asList(ids)));
    }

}
